/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Formularios;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author FRANCISCO
 */
public class estadisticas extends javax.swing.JFrame {

    /**
     * Creates new form estadisticas
     */
    public estadisticas() {
        initComponents();
         this.setLocationRelativeTo(null);
        this.setResizable(false);
        txttotal.setEditable(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        btnbus = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        txtfecha = new javax.swing.JFormattedTextField();
        txttotal = new javax.swing.JTextField();
        TOTAL = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("ESTADISTICAS");
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("ESTADISTICAS");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 10, 218, 22));
        getContentPane().add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 40, 550, 20));

        btnbus.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        btnbus.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/Search-icon.png"))); // NOI18N
        btnbus.setText("MOSTRAR");
        btnbus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnbusActionPerformed(evt);
            }
        });
        btnbus.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                btnbusKeyPressed(evt);
            }
        });
        getContentPane().add(btnbus, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 90, -1, -1));

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("DIA");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 90, -1, -1));

        try {
            txtfecha.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("####-##-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        getContentPane().add(txtfecha, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 90, 150, 30));

        txttotal.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        getContentPane().add(txttotal, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 260, 370, 40));

        TOTAL.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        TOTAL.setForeground(new java.awt.Color(255, 255, 255));
        TOTAL.setText("TOTAL");
        getContentPane().add(TOTAL, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 200, -1, -1));

        jButton2.setText("SALIR");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(450, 330, -1, -1));

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/energia_azul-1024x768.jpg"))); // NOI18N
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 540, 370));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        Plataforma pla = new Plataforma();
        pla.setVisible(true);
        dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void btnbusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnbusActionPerformed
        buscarfecha();
    }//GEN-LAST:event_btnbusActionPerformed

    private void btnbusKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_btnbusKeyPressed
      if(evt.getKeyCode()== java.awt.event.KeyEvent.VK_ENTER){
        buscarfecha();
    }//GEN-LAST:event_btnbusKeyPressed
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(estadisticas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(estadisticas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(estadisticas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(estadisticas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new estadisticas().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel TOTAL;
    private javax.swing.JButton btnbus;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JFormattedTextField txtfecha;
    private javax.swing.JTextField txttotal;
    // End of variables declaration//GEN-END:variables

    private void buscarfecha() {
        try {

            DriverManager.registerDriver(new org.gjt.mm.mysql.Driver());
            try (Connection conexion = DriverManager.getConnection("jdbc:mysql://localhost/pasteleria1211","root", "12345")) {
               
                Statement s = conexion.createStatement();

                ResultSet rs = s.executeQuery("call totaldeldia('"+txtfecha.getText()+"');");
                
               
          
            
            while (rs.next()) {
                Object[] fila = new Object[1];
                for (int j = 0; j < 1; j++) {
                    fila[j] = rs.getObject(j + 1);
                    
                    
                    
                    
                    

                       txttotal.setText(rs.getObject(j+1).toString());
                
                     System.out.println(j);
                        System.out.println(rs.getObject(j+1).toString());
                }
    
            }}
            }   catch (SQLException s) {
                      JOptionPane.showMessageDialog(null, s, "no se encontro al usuario" + s, JOptionPane.ERROR_MESSAGE);
             }
    }
}
